/// <summary>
// CodeFx - A .NET framework
// Laurent Morisseau
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Laurent Morisseau
/// </summary>
/// <author><a href="mailto:laurent.morisseau@gmail.com">Laurent Morisseau</a></author>

namespace CodeFx.Web
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Text;

    public class ScenariiPersistanceCollection : ConfigurationElementCollection
    {
        #region Collection

        private static ConfigurationPropertyCollection _properties;

        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return _properties;
            }
        }

        #endregion

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }
        protected override string ElementName
        {
            get
            {
                return "Scenario";
            }
        }

        #region Constructeurs

        static ScenariiPersistanceCollection()
        {
            _properties = new ConfigurationPropertyCollection();
        }

        public ScenariiPersistanceCollection()
        {
        }

        #endregion

        #region Implementation des methodes abstraites de ConfigurationElementCollection

        protected override ConfigurationElement CreateNewElement()
        {
            return new ScenarioPersistanceElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            ScenarioPersistanceElement scenarioPersistance = element as ScenarioPersistanceElement;
            if (element != null)
            {
                return scenarioPersistance.Scenario;
            }
            else
            {
                return null;
            }
        }

        #endregion

        #region Indexers

        public ScenarioPersistanceElement this[int index]
        {
            get
            {
                ScenarioPersistanceElement element = base.BaseGet(index) as ScenarioPersistanceElement;
                if (element == null)
                {
                    element = new ScenarioPersistanceElement();
                }
                return element;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                base.BaseAdd(index, value);
            }
        }

        public new ScenarioPersistanceElement this[string name]
        {
            get
            {
                ScenarioPersistanceElement element = base.BaseGet(name) as ScenarioPersistanceElement;
                if (element == null)
                {
                    element = new ScenarioPersistanceElement();
                }
                return element;
            }
        }

        #endregion
    }
}
